// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

export enum colorList {
    normal = 0,
    red = 1,
    green = 2,
    blue = 3
}

@ccclass
export default class bgColorControl extends cc.Component {

    @property({
        type : cc.Enum(colorList),
        displayName : "当前颜色"
    })
    curColor : colorList = colorList.red;

    @property(cc.Node)
    bgNode : cc.Node[] = [];

    onLoad () {
        if(this.curColor != colorList.normal){
            this.bgNode[this.curColor - 1].active = true;
        }

        cc.game.on("setColor",(res)=>{
            this.updateBackColor(res);
        })
    }

    protected onDestroy(): void {
        cc.game.off("setColor");
    }

    updateBackColor(color){
        for(let i in this.bgNode){
            if(color == parseInt(i) + 1){
                this.bgNode[i].active = true;
            }else{
                this.bgNode[i].active = false;
            }
        }
    }

}
